package iqq.ui.widget;

import iqq.im.bean.QQUser.QQUserStatus;
import iqq.util.StatusUtils;
import iqq.util.Strings;

import java.awt.Component;

import javax.swing.DefaultComboBoxModel;
import javax.swing.Icon;
import javax.swing.JList;

import com.alee.laf.combobox.WebComboBox;
import com.alee.laf.combobox.WebComboBoxCellRenderer;
import com.alee.laf.label.WebLabel;

/**
 * @author ChenZhiHui
 * @create-time 2013-3-8
 */
public class StatusComboBox extends WebComboBox {

	public StatusComboBox() {
		super();
		initStatusComboBox();
		initStatusLbl();
	}

	private void initStatusLbl() {
		DefaultComboBoxModel<WebLabel> cbxModel = new DefaultComboBoxModel<WebLabel>();
		QQUserStatus[] status = QQUserStatus.values();
		for (QQUserStatus state : status) {
			System.out.println(state.getName());
			cbxModel.addElement(StatusUtils.statusToLabel(state));

		}
		this.setModel(cbxModel);
	}

	@SuppressWarnings("unchecked")
	private void initStatusComboBox() {

		this.setRenderer(new WebComboBoxCellRenderer(this) {
			public Component getListCellRendererComponent(JList list,
					Object value, int index, boolean isSelected,
					boolean cellHasFocus) {

				WebLabel renderer = (WebLabel) super
						.getListCellRendererComponent(list, value, index,
								isSelected, cellHasFocus);
				WebLabel defaultFileFilter = (WebLabel) value;
				if (defaultFileFilter != null) {
					Icon icon = defaultFileFilter.getIcon();
					String val = defaultFileFilter.getText();
					if (icon != null) {
						renderer.setIcon(icon);
					}
					if (!Strings.isEmpty(val)) {
						renderer.setText(val);
					}
				}
				return renderer;
			}
		});

	}
}
